var result;
function userConfig(){
    var row = $('#dgUser').datagrid('getSelected');
     if(!row){
         showInfoMsg("请选择一条记录!");
         return;
     }
    var empCode = row.empCode;
    var url = G_CTX_PATH+"/CsUserController/findByCode.do";
    $("#agentName").textbox('setValue',row.empName);
    $('#userId').textbox('setValue',row.empCode);
    var data = {'empCode':empCode};
    findByCode(url,data);
    if(result != 0){//回显
        $("#isExistence").val("1");
        $("#ctiOpenid").textbox('setValue',result.ctiOpenid);
        $("#ctiPwd").textbox('setValue',result.ctiPwd);
        $("#remark").textbox('setValue',result.remark);
    }else{
        $("#isExistence").val("");
    }
    //通过code去查找是否含有这个信息
    openDialog("dlUserConfig", "话务配置");
}

//保存配置
function saveConfig(){
    var url = G_CTX_PATH+"/CsUserController/save.do"
    $("#userConfigFromId").form("submit", {
        url: url,
        novalidate: true,
        ajax: true,
        success: function (data) {
             data = JSON.parse(data);
            if(data.success){
                if (data.data > 0) {
                    showInfoMsg("数据保存成功!");
                    closeDialog('dlUserConfig');
                    $("#userConfigFromId").form('reset');
                } else {
                    showInfoMsg("数据保存失败!");
                }
            }else{
                showInfoMsg(data.message);
            }

        }
    });
}

//查找
function findByCode(url,data){
    $.ajax({
        type: "POST",
        url: url,
        data: data,
        async:false,
        success : function(data){
            if(data.success){
             result = data.data;
             console.log(result);
            }
        }
    });
}

function cancleConfig(){
    closeDialog('dlUserConfig');
    $("#userConfigFromId").form('reset');
}




